package old;

import java.io.IOException;

import javax.jdo.JDOObjectNotFoundException;
import javax.jdo.PersistenceManager;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import robot.PMF;

import modeles.Pages;


public class ModifierPagesServlet extends HttpServlet {

	private static final long serialVersionUID = 2243512459117102470L;
	
	public void doPost(HttpServletRequest req, HttpServletResponse resp)	throws IOException {
		String nomPage = req.getParameter("nomPage");
		String url = req.getParameter("url");
		String contenu = req.getParameter("contenu");
		PersistenceManager pm = PMF.get().getPersistenceManager();
		Pages pageCourant = null;
		try{
        		pageCourant = pm.getObjectById(Pages.class,nomPage);
        		pageCourant.setContent(contenu);
		}catch(JDOObjectNotFoundException e){
        		pageCourant = new Pages(contenu, nomPage);
        }
        
        try {
            pm.makePersistent(pageCourant);
        } finally {
            pm.close();
        }
        
		resp.sendRedirect(url);
	}
}
